/************************************************************************
 *                                                                      *
 *      R T X  - 5 1    System Header File                              *
 *                                                                      *
 *----------------------------------------------------------------------*
 *                                                                      *
 *      Filename:       RTX51.H                                         *
 *      Language:       Keil C (C51)                                    *
 *      Dev.system:     Keil uVision2                                   *
 *      Targetsystem:   Any system based upon 8051 up                   *
 *                                                                      *
 *      Purpose:        User Interface for RTX-51.                      *
 *                                                                      *
 *----------------------------------------------------------------------*
 * Rev. | Released   | Programmer| Comments                             *
 *----------------------------------------------------------------------*
 * 5.00 | 19.10.94   | Gl        | Release 5.00                         *
 * 7.00 | 13.11.2001 | TM        | Release 7.00 no changes on interface *
 ************************************************************************
 *    Copyright 1991 .. 2001 METTLER  &  FUCHS  AG,  CH-8953 Dietikon   *
 ************************************************************************/

/* General system function return values */
#define OK  0
#define NOT_OK -1

/* Return values for system function os_wait */
#define MSG_EVENT 1
#define INT_EVENT 2
#define SIG_EVENT 3
#define TMO_EVENT 4
#define SEM_EVENT 5

/* Event selectors for system function os_wait */
#define K_MBX  0x10
#define K_INT  0x20
#define K_SIG  0x40
#define K_TMO  0x80
#define K_IVL  0x00

/* Constants for system calls os_check_tasks and os_check_task */
#define K_READY   0
#define K_RUNNING 1
#define K_BLOCKED 2
#define K_DELETED 3


/* Type definition for system call os_check_mailboxes */
typedef struct {
            unsigned char message_cnt;
            unsigned char read_task_cnt;
            unsigned char write_task_cnt;
        } t_rtx_allmbxtab[8];

/* Type definition for system call os_check_mailbox */
typedef struct {
            unsigned char message_cnt;
            unsigned char read_task_cnt;
            unsigned char write_task_cnt;
            unsigned char wait_tasks[16];
            unsigned int messages[8];
        } t_rtx_onembxtab;

/* Type definition for system call os_check_semaphores */
typedef struct {
            /* 0=token stored;
               1=no token stored/no waiting tasks;
               2=no token stored/ waiting tasks         */
            unsigned char status;
        } t_rtx_allsemtab[8];

/* Type definition for system call os_check_semaphore */
typedef struct {
            unsigned char token_flag;
            unsigned char task_count;
            unsigned char wait_tasks[15];
        } t_rtx_onesemtab;

/* Type definition for system call os_check_tasks */
typedef struct {
            unsigned char task_number;
            unsigned char state;
        } t_rtx_alltasktab[19];

/* Type definition for system call os_check_task */
typedef struct {
            unsigned char state;
            unsigned int flags;
        } t_rtx_onetasktab;

/* Type definition for system call os_check_pool */
typedef struct {
            void xdata *block;
            unsigned char task_number;
        } t_rtx_blockinfo[255];


/* RTX-51 System Functions  */
#pragma SAVE
#pragma REGPARMS

extern signed char os_start_system (unsigned char task_number);
extern signed char os_create_task (unsigned char task_number);
extern signed char os_delete_task (unsigned char task_number);
extern unsigned char os_running_task_id (void);
extern signed char os_attach_interrupt (unsigned char interrupt_nbr);
extern signed char os_detach_interrupt (unsigned char interrupt_nbr);
extern signed char os_enable_isr (unsigned char interrupt_nbr);
extern signed char os_disable_isr (unsigned char interrupt_nbr);
extern signed char os_wait (unsigned char event_selector,
                            unsigned char timeout,
                            unsigned int xdata *message);
/* special os_wait definitions for call with two parameters */
extern signed char os_wait2 (unsigned char event_selector,
                             unsigned char timeout);
extern signed char os_send_message (unsigned char mailbox,
                                    unsigned int message,
                                    unsigned char timeout);
extern signed char os_send_signal (unsigned char task_number);
extern signed char os_clear_signal (unsigned char task_number);
extern signed char os_set_slice (unsigned int timeslice);
extern signed char isr_send_message (unsigned char mailbox,
                                     unsigned int message);
extern signed char isr_send_signal (unsigned char task_number);
extern signed char isr_recv_message (unsigned char mailbox,
                                     unsigned int xdata *message);
extern signed char os_send_token (unsigned char semaphore);
extern signed char os_create_pool (unsigned int block_size,
                                   void xdata *memory,
                                   unsigned int mem_size);
extern void xdata *os_get_block (unsigned int block_size);
extern signed char os_free_block (unsigned int block_size,
                                  void xdata *block);
extern signed char os_check_mailboxes (t_rtx_allmbxtab xdata *table);
extern signed char os_check_mailbox (unsigned char mailbox,
                                     t_rtx_onembxtab xdata *table);
extern signed char os_check_semaphores (t_rtx_allsemtab xdata *table);
extern signed char os_check_semaphore (unsigned char semaphore,
                                     t_rtx_onesemtab xdata *table);
extern signed char os_check_tasks (t_rtx_alltasktab xdata *table);
extern signed char os_check_task (unsigned char task_number,
                                  t_rtx_onetasktab xdata *table);
extern signed char os_check_pool (unsigned int block_size,
                                  t_rtx_blockinfo xdata *table);
extern signed char oi_set_int_masks (unsigned char ien0,
                                     unsigned char ien1,
                                     unsigned char ien2);
extern signed char oi_reset_int_masks (unsigned char ien0,
                                       unsigned char ien1,
                                       unsigned char ien2);

/*----------------------------------------------------------------------
 *      END OF HEADER FILE
 *----------------------------------------------------------------------*/
#pragma RESTORE
